<?php
	require 'include.php';
	$equipe = (!empty($_REQUEST['equipe'])) ? $_REQUEST['equipe'] : "";
	$delete = (!empty($_REQUEST['del'])) ? $_REQUEST['del'] : "";
	$communication = (!empty($_REQUEST['communication'])) ? $_REQUEST['communication'] : "";
	if($user_id = check_cookie()){
		$user = new membre($user_id);
		if(array_key_exists($equipe,$user->equipes)){
			if($communication){
				if($delete){
					$q = "delete from communications where membre_id = $user_id and id = $communication";
				}
				else{
					$q = "insert into communications (membre_id, equipe_id, corps, date) values ($user_id,$equipe,'".(addslashes($communication))."',curdate())";					
				}
				echo (ExecRequete($q)) ? 1 : 0;
			}
			else{
				echo "<form action = 'communications.php' id = 'form_communication' name = 'form_communication' method = 'post' >\n";
				echo "<p class = 'fade'>$user->prenom $user->nom ".(date("d.m.Y"))."</p>\n";
				echo "<textarea name = 'communication' rows = '10' cols = '33'></textarea>\n";
				echo "<p class = 'center'><button type = 'button' onclick = 'add_communication(\"$equipe\")'>enregistrer</button>\n";
				echo "<input type = 'hidden' name = 'equipe' value = '$equipe' /></p>\n";
				echo "</form>\n";	
			}
		}
	}
?>